﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Data;
using System.Reflection;
using System.Collections;
using System.Configuration;
using Tipler.DataSetler;
//using Aspose.Words.ReportingServices;

namespace IKYSWeb.Raporlar
{
    public partial class Raporlar_RaporGoruntule : System.Web.UI.Page
    {
        protected DataSet dsRaporum
        {
            get
            {
                return (DataSet)Session["dsRaporum"];
            }
            set
            {
                Session["dsRaporum"] = value;
            }
        }

        protected string RaporPath
        {
            get
            {
                if (Session["RaporPath"] != null)
                    return Session["RaporPath"].ToString();
                else
                    return string.Empty;
            }
            set
            {
                Session["RaporPath"] = value;
            }
        }

        public void ItemsSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
        {
            DataSet ds = new DataSet();


            switch (e.ReportPath)
            {
                case "SubHizmetBorclanmasi":
                    if (Session["BorclanmaDS"] != null)
                        ds = (DataSet)Session["BorclanmaDS"];
                    e.DataSources.Add(new ReportDataSource("DSHizmetBorclanmaRapor_dtHizmetBorclanma", ds.Tables[0]));
                    break;
            }

        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    rtpRaporum.Reset();
                    rtpRaporum.LocalReport.DataSources.Clear();
                    rtpRaporum.ProcessingMode = ProcessingMode.Local;
                    rtpRaporum.ShowToolBar = true;
                    rtpRaporum.LocalReport.DataSources.Clear();
                    rtpRaporum.LocalReport.EnableExternalImages = true;

                  

                    rtpRaporum.LocalReport.ReportPath = Server.MapPath("/Rapor/" + this.RaporPath);

                    //Dataset bağlanmazsa hata veriyor Özlem
                    if (dsRaporum != null)
                    {
                        foreach (DataTable dt in dsRaporum.Tables)
                        {
                            rtpRaporum.LocalReport.DataSources.Add(new ReportDataSource(dt.TableName, dt));
                        }
                    }



                    if (this.RaporPath.Contains("xx.rdlc"))
                    //  || buraya logo olması gereken rapor adları eklenecek 
                    {
                        ReportParameter logoURL = new ReportParameter();
                        logoURL.Name = "LogoURL";
                        logoURL.Values.Add(Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "") + "/App_Themes/ApplicationBlue/images/logo_kucuk.gif");

                        ReportParameter[] parameters = { logoURL };

                        rtpRaporum.LocalReport.SetParameters(parameters);
                    }

                }
                catch (Exception exx)
                {
                    //rtpRaporum.LocalReport.GetParameters();
                    BasePage.EventLogYaz("RaporGoruntule.aspx de hata:" + exx.Message + " Rapor Adı : " + this.RaporPath, System.Diagnostics.EventLogEntryType.Error);
                    return;
                }
            }
        }
    }
}